import { DailyItem } from "./DailyItem";
import { SWildBossInfo } from "../../../../../Message/Public/SWildBossInfo";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../../extend/language/Language";
import { ClockManager } from "../../../manager/ClockManager";
import { RemainTimeTool } from "../../award/RemainTimeTool";
import { SecTimer } from "../../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../../com/gengine/core/frame/TimerType";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { DailyAwardItem } from "../reward/DailyAwardItem";
import { EReward } from "../../../../../Message/Public/EReward";
import { DailyInfo } from "../../../model/DailyInfo";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
//class DailyBossItem
    
    export  class DailyBossItem extends DailyItem
    {
        constructor()
        {
            super();
            return;
        }

        public updateBossRefreshInfo(arg1: SWildBossInfo): void
        {
            this._bossInfo = arg1;
            this.stopRefreshTime();
            if (arg1) 
            {
                if (arg1.bLive) 
                {
                    _itemTime.htmlText = HTMLUtil.addColor(Language.getString(20968), "#ffff00");
                }
                else if (info.flyFoot) 
                {
                    _itemTime.htmlText = HTMLUtil.addColor(_info.time, "#f6ff00");
                }
                else if (this._bossInfo.refreshDt.time - ClockManager.instance.nowDate.time > 0) 
                {
                    _itemTime.htmlText = HTMLUtil.addColor(Language.getString(20969) + "  " + RemainTimeTool.getRemainTimeBySeconds((this._bossInfo.refreshDt.time - ClockManager.instance.nowDate.time) / 1000), "ff0000");
                    this.startRefreshTime();
                }
                else 
                {
                    _itemTime.htmlText = HTMLUtil.addColor(Language.getString(20969) + "  00: 00: 00", "ff0000");
                }
            }
            return;
        }

        protected startRefreshTime(): void
        {
            if (!this._timer) 
            {
                this._timer = new SecTimer(1);
                this._timer.addListener(TimerType.ENTERFRAME, this.onTimerHandler);
            }
            if (this._bossInfo) 
            {
                this._timer.repeatCount = (this._bossInfo.refreshDt.time - ClockManager.instance.nowDate.time) / 1000;
                if (!this._timer.running) 
                {
                    this._timer.start();
                }
            }
            else 
            {
                this.stopRefreshTime();
            }
            return;
        }

        protected onTimerHandler(arg1: SecTimer): void
        {
            _itemTime.htmlText = HTMLUtil.addColor(Language.getString(20969) + "  " + RemainTimeTool.getRemainTimeBySeconds(arg1.repeatCount), "ff0000");
            return;
        }

        protected stopRefreshTime(): void
        {
            if (this._timer && this._timer.running) 
            {
                this._timer.stop();
                this._timer.isDelete = false;
            }
            return;
        }

        public /* override */ initUI(): void
        {
            super.initUI();
            this._nameBg = ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB);
            this._nameBg.width = 88;
            this._nameBg.height = 32;
            this._nameBg.x = 2;
            this._nameBg.y = 4;
            addChildAt(this._nameBg, 0);
            _itemName.defaultTextFormat = new GTextFormat(FontUtil.xingkaiName, 20, 16187136, false);
            _itemName.y = 8;
            _itemName.x = _itemName.x + 3;
            _itemName.filters = [FilterConst.glowFilter];
            _itemLevel.x = _itemLevel.x + 13;
            this._rewardStar = new DailyAwardItem(EReward._ERewardItem);
            this._rewardStar.x = this._nameBg.x + this._nameBg.width + 4;
            this._rewardStar.y = 20;
            addChild(this._rewardStar);
            var loc1=new GTextFormat("", 12, 11464703);
            loc1.align = flash.text.TextFormatAlign.CENTER;
            _itemTime.defaultTextFormat = loc1;
            _itemTime.wordWrap = true;
            _itemTime.multiline = true;
            _itemTime.textColor = 16187136;
            _itemTime.width = 100;
            _itemTime.height = 50;
            _itemTime.filters = [FilterConst.nameGlowFilter];
            _itemTime.x = 220;
            _itemTime.y = 12;
            _itemOpt.x = 340;
            _itemOpt.y = 20;
            this._mapName = new Object /* flash.text.TextField */();
            this._mapName.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._mapName.width = 100;
            this._mapName.x = 375;
            this._mapName.y = 4;
            this._mapName.textColor = 16776960;
            this._mapName.text = "龙雪域";
            this._mapName.mouseEnabled = false;
            this._mapName.filters = [FilterConst.nameGlowFilter];
            addChild(this._mapName);
            _flyFoot.y = 20;
            _line.y = 40;
            return;
        }

        public /* override */ updateData(arg1: DailyInfo): void
        {
            var loc1=null;
            super.updateData(arg1);
            if (arg1.levelWorld != 1) 
            {
                _itemLevel.htmlText = HTMLUtil.addColor(Language.getStringByParam(90108, arg1.level.toString()), _color);
            }
            else 
            {
                _itemLevel.htmlText = HTMLUtil.addColor(Language.getStringByParam(20970, arg1.level.toString()), _color);
            }
            _itemOpt.htmlText = "";
            if (arg1.flyFoot) 
            {
                _itemOpt.htmlText = "<u><a href=\'event: 0\'>" + HTMLUtil.addColor(arg1.bossPoint, "#00ff00") + "</u></a>";
                _itemOpt.x = 340;
            }
            else 
            {
                _itemOpt.htmlText = HTMLUtil.addColor(arg1.bossPoint, "#00ff00");
                _itemOpt.x = 347;
            }
            this._mapName.htmlText = HTMLUtil.addColor(arg1.target.mapName, "#AEEFFF");
            _itemTime.htmlText = HTMLUtil.addColor(_info.time, "#f6ff00");
            _itemName.htmlText = HTMLUtil.addColor(_info.name, "#f6ff00");
            if (_info.flyFoot) 
            {
                _flyFoot.x = _itemOpt.x + _itemOpt.textWidth + 5;
            }
            var loc2=0;
            var loc3=arg1.award;
            for(loc1 of loc3) 
            {
                if (loc1.type != EReward._ERewardItem) 
                {
                    continue;
                }
                this._rewardStar.updateData(loc1.value, loc1.type, loc1.value);
            }
            return;
        }

        public /* override */ dispose(): void
        {
            super.dispose();
            this._rewardStar.dispose();
            this.stopRefreshTime();
            this._bossInfo = null;
            return;
        }

        public /* override */ get height(): number
        {
            return 40;
        }

        protected /* var */_nameBg: ScaleBitmap;

        protected /* var */_mapName: Object /* flash.text.TextField */;

        protected /* var */_rewardStar: DailyAwardItem;

        protected /* var */_bossInfo: SWildBossInfo;

        protected /* var */_timer: SecTimer;
    }
